// import mapjson from './map.json'
import { Local } from '../utils/storage'

export default class Map {
    private mapInfo: TMap
    constructor() {
        this.mapInfo = Local.get("tt15_map")
        // this.mapInfo = mapjson
    }

    public getGroundSize() {
        const width = this.mapInfo.header.maxPos.x! - this.mapInfo.header.minPos.x!
        const height = this.mapInfo.header.maxPos.y! - this.mapInfo.header.minPos.y!
        return {
            width,
            height
        }
    }

    public getGroundCenter() {
        // fork agv 
        const centerX = (this.mapInfo.header.maxPos.x! + this.mapInfo.header.minPos.x!) * 0.5
        const centerY = (this.mapInfo.header.maxPos.y! - this.mapInfo.header.minPos.y!) * 0.3

        return {
            x: centerX,
            z: centerY,
        }
    }


    public getStraightPath() {
        const path = this.mapInfo.advancedCurveList.filter((path) => {
            return path.className === "StraightPath"
        })
        return path
    }

    public getBezierPath() {
        const path = this.mapInfo.advancedCurveList.filter((path) => {
            return path.className === "BezierPath" || (path.className === "DegenerateBezier")
        })
        return path
    }

    public getOtherPath() {
        const path = this.mapInfo.advancedCurveList.filter((path) => {
            return path.className !== "BezierPath" && (path.className !== "StraightPath") && (path.className !== "DegenerateBezier")
        })
        return path
    }

    public getStations() {
        return this.mapInfo.advancedPointList
    }

    public static handleStationName(name: string) {
        if (name.startsWith("AP")) {
            return "AP"
        }
        if (name.length > 3) {
            return name.split("LM")[1]
        } else {
            return "0" + name.split("LM")[1]
        }
    }

    public getPoints() {
        return this.mapInfo.normalPosList
    }


}

